<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LINE 1 &quot;libraries\\Win32\\System\\Win32\\FileMapping.hsc&quot; #-}</span><span id="local-6989586621679115248"></span><span id="local-6989586621679115224"></span><span id="local-6989586621679115220"><span id="local-6989586621679115221"></span></span><span>
</span><span id="line-1"></span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LINE 2 &quot;libraries\\Win32\\System\\Win32\\FileMapping.hsc&quot; #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE Safe #-}</span><span>
</span><span id="line-3"></span><span>
</span><span id="line-4"></span><span class="hs-pragma">{-# LINE 6 &quot;libraries\\Win32\\System\\Win32\\FileMapping.hsc&quot; #-}</span><span>
</span><span id="line-6"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- Module      :  System.Win32.FileMapping</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Copyright   :  (c) Esa Ilari Vuokko, 2006</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- License     :  BSD-style (see the file LICENSE)</span><span>
</span><span id="line-11"></span><span class="hs-comment">--</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Maintainer  :  Esa Ilari Vuokko &lt;ei@vuokko.info&gt;</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Stability   :  provisional</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-15"></span><span class="hs-comment">--</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- A collection of FFI declarations for interfacing with Win32 mapped files.</span><span>
</span><span id="line-17"></span><span class="hs-comment">--</span><span>
</span><span id="line-18"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-19"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">System.Win32.FileMapping</span><span>
</span><span id="line-20"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">mapFile</span><span>
</span><span id="line-21"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MappedObject</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-22"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">withMappedFile</span><span>
</span><span id="line-23"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">withMappedArea</span><span>
</span><span id="line-24"></span><span>      </span><span class="hs-comment">-- * Enums</span><span>
</span><span id="line-25"></span><span>      </span><span class="hs-comment">-- ** Section protection flags</span><span>
</span><span id="line-26"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ProtectSectionFlags</span><span>
</span><span id="line-27"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">sEC_COMMIT</span><span>
</span><span id="line-28"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">sEC_IMAGE</span><span>
</span><span id="line-29"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">sEC_NOCACHE</span><span>
</span><span id="line-30"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">sEC_RESERVE</span><span>
</span><span id="line-31"></span><span>      </span><span class="hs-comment">-- ** Access falgs</span><span>
</span><span id="line-32"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">FileMapAccess</span><span>
</span><span id="line-33"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">fILE_MAP_ALL_ACCESS</span><span>
</span><span id="line-34"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">fILE_MAP_COPY</span><span>
</span><span id="line-35"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">fILE_MAP_READ</span><span>
</span><span id="line-36"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">fILE_MAP_WRITE</span><span>
</span><span id="line-37"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">fILE_SHARE_WRITE</span><span>
</span><span id="line-38"></span><span>
</span><span id="line-39"></span><span>      </span><span class="hs-comment">-- * Mapping files</span><span>
</span><span id="line-40"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">createFileMapping</span><span>
</span><span id="line-41"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">openFileMapping</span><span>
</span><span id="line-42"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">mapViewOfFileEx</span><span>
</span><span id="line-43"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">mapViewOfFile</span><span>
</span><span id="line-44"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">unmapViewOfFile</span><span>
</span><span id="line-45"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Win32.Types</span><span>   </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">HANDLE</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">DWORD</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">BOOL</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">SIZE_T</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">LPCTSTR</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">withTString</span><span>
</span><span id="line-48"></span><span>                            </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">failIf</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">failIfNull</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">DDWORD</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ddwordToDwords</span><span>
</span><span id="line-49"></span><span>                            </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">iNVALID_HANDLE_VALUE</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Win32.Mem</span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Win32.File</span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Win32.Info</span><span>
</span><span id="line-53"></span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Control.Exception</span><span>        </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">mask_</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">bracket</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-55"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign</span><span>                  </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">Ptr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">nullPtr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">plusPtr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">maybeWith</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">FunPtr</span><span>
</span><span id="line-56"></span><span>                                </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ForeignPtr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">newForeignPtr</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C.Types</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">CUIntPtr</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-cpp">

#include &quot;windows_cconv.h&quot;
</span><span>
</span><span id="line-61"></span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span class="hs-comment">---------------------------------------------------------------------------</span><span>
</span><span id="line-64"></span><span class="hs-comment">-- Derived functions</span><span>
</span><span id="line-65"></span><span class="hs-comment">---------------------------------------------------------------------------</span><span>
</span><span id="line-66"></span><span>
</span><span id="line-67"></span><span class="hs-comment">-- | Maps file fully and returns ForeignPtr and length of the mapped area.</span><span>
</span><span id="line-68"></span><span class="hs-comment">-- The mapped file is opened read-only and shared reading.</span><span>
</span><span id="line-69"></span><span class="hs-identifier">mapFile</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">FilePath</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ForeignPtr</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Int</span><span class="hs-special">)</span><span>
</span><span id="line-70"></span><span class="hs-identifier">mapFile</span><span> </span><span class="hs-identifier">path</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-71"></span><span>    </span><span class="hs-identifier">bracket</span><span>
</span><span id="line-72"></span><span>        </span><span class="hs-special">(</span><span class="hs-identifier">createFile</span><span> </span><span class="hs-identifier">path</span><span> </span><span class="hs-identifier">gENERIC_READ</span><span> </span><span class="hs-identifier">fILE_SHARE_READ</span><span> </span><span class="hs-identifier">Nothing</span><span> </span><span class="hs-identifier">oPEN_EXISTING</span><span> </span><span class="hs-identifier">fILE_ATTRIBUTE_NORMAL</span><span> </span><span class="hs-identifier">Nothing</span><span class="hs-special">)</span><span>
</span><span id="line-73"></span><span>        </span><span class="hs-special">(</span><span class="hs-identifier">closeHandle</span><span class="hs-special">)</span><span>
</span><span id="line-74"></span><span>        </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">fh</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">bracket</span><span>
</span><span id="line-75"></span><span>            </span><span class="hs-special">(</span><span class="hs-identifier">createFileMapping</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">fh</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">pAGE_READONLY</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-identifier">Nothing</span><span class="hs-special">)</span><span>
</span><span id="line-76"></span><span>            </span><span class="hs-special">(</span><span class="hs-identifier">closeHandle</span><span class="hs-special">)</span><span>
</span><span id="line-77"></span><span>            </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">fm</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-78"></span><span>                </span><span class="hs-identifier">fi</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getFileInformationByHandle</span><span> </span><span class="hs-identifier">fh</span><span>
</span><span id="line-79"></span><span>                </span><span class="hs-identifier">fp</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mask_</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-80"></span><span>                    </span><span class="hs-identifier">ptr</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">mapViewOfFile</span><span> </span><span class="hs-identifier">fm</span><span> </span><span class="hs-identifier">fILE_MAP_READ</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-81"></span><span>                    </span><span class="hs-identifier">newForeignPtr</span><span> </span><span class="hs-identifier">c_UnmapViewOfFileFinaliser</span><span> </span><span class="hs-identifier">ptr</span><span>
</span><span id="line-82"></span><span>                </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fp</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">bhfiSize</span><span> </span><span class="hs-identifier">fi</span><span class="hs-special">)</span><span>
</span><span id="line-83"></span><span>
</span><span id="line-84"></span><span class="hs-keyword">data</span><span> </span><span class="hs-identifier">MappedObject</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">MappedObject</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-identifier">FileMapAccess</span><span>
</span><span id="line-85"></span><span>
</span><span id="line-86"></span><span class="hs-comment">-- | Opens an existing file and creates mapping object to it.</span><span>
</span><span id="line-87"></span><span class="hs-identifier">withMappedFile</span><span>
</span><span id="line-88"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">FilePath</span><span>             </span><span class="hs-comment">-- ^ Path</span><span>
</span><span id="line-89"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Bool</span><span>                 </span><span class="hs-comment">-- ^ Write? (False = read-only)</span><span>
</span><span id="line-90"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">Bool</span><span>           </span><span class="hs-comment">-- ^ Sharing mode, no sharing, share read, share read+write</span><span>
</span><span id="line-91"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Integer</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">MappedObject</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- ^ Action</span><span>
</span><span id="line-92"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-93"></span><span class="hs-identifier">withMappedFile</span><span> </span><span class="hs-identifier">path</span><span> </span><span class="hs-identifier">write</span><span> </span><span class="hs-identifier">share</span><span> </span><span class="hs-identifier">act</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-94"></span><span>    </span><span class="hs-identifier">bracket</span><span>
</span><span id="line-95"></span><span>        </span><span class="hs-special">(</span><span class="hs-identifier">createFile</span><span> </span><span class="hs-identifier">path</span><span> </span><span class="hs-identifier">access</span><span> </span><span class="hs-identifier">share'</span><span> </span><span class="hs-identifier">Nothing</span><span> </span><span class="hs-identifier">oPEN_EXISTING</span><span> </span><span class="hs-identifier">fILE_ATTRIBUTE_NORMAL</span><span> </span><span class="hs-identifier">Nothing</span><span class="hs-special">)</span><span>
</span><span id="line-96"></span><span>        </span><span class="hs-special">(</span><span class="hs-identifier">closeHandle</span><span class="hs-special">)</span><span>
</span><span id="line-97"></span><span>        </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">fh</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">bracket</span><span>
</span><span id="line-98"></span><span>            </span><span class="hs-special">(</span><span class="hs-identifier">createFileMapping</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">fh</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">page</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-identifier">Nothing</span><span class="hs-special">)</span><span>
</span><span id="line-99"></span><span>            </span><span class="hs-special">(</span><span class="hs-identifier">closeHandle</span><span class="hs-special">)</span><span>
</span><span id="line-100"></span><span>            </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">fm</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-101"></span><span>                </span><span class="hs-identifier">bhfi</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getFileInformationByHandle</span><span> </span><span class="hs-identifier">fh</span><span>
</span><span id="line-102"></span><span>                </span><span class="hs-identifier">act</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">bhfiSize</span><span> </span><span class="hs-identifier">bhfi</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">MappedObject</span><span> </span><span class="hs-identifier">fh</span><span> </span><span class="hs-identifier">fm</span><span> </span><span class="hs-identifier">mapaccess</span><span class="hs-special">)</span><span>
</span><span id="line-103"></span><span>    </span><span class="hs-keyword">where</span><span>
</span><span id="line-104"></span><span>        </span><span class="hs-identifier">access</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">write</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">gENERIC_READ</span><span class="hs-operator">+</span><span class="hs-identifier">gENERIC_WRITE</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">gENERIC_READ</span><span>
</span><span id="line-105"></span><span>        </span><span class="hs-identifier">page</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">write</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">pAGE_READWRITE</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">pAGE_READONLY</span><span>
</span><span id="line-106"></span><span>        </span><span class="hs-identifier">mapaccess</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">write</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">fILE_MAP_ALL_ACCESS</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">fILE_MAP_READ</span><span>
</span><span id="line-107"></span><span>        </span><span class="hs-identifier">share'</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">share</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-108"></span><span>            </span><span class="hs-identifier">Nothing</span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">fILE_SHARE_NONE</span><span>
</span><span id="line-109"></span><span>            </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">False</span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">fILE_SHARE_READ</span><span>
</span><span id="line-110"></span><span>            </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">True</span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">fILE_SHARE_READ</span><span> </span><span class="hs-operator">+</span><span> </span><span class="hs-identifier">fILE_SHARE_WRITE</span><span>
</span><span id="line-111"></span><span>
</span><span id="line-112"></span><span class="hs-comment">-- | Maps area into memory.</span><span>
</span><span id="line-113"></span><span class="hs-identifier">withMappedArea</span><span>
</span><span id="line-114"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">MappedObject</span><span>     </span><span class="hs-comment">-- ^ Mapped object, from withMappedFile</span><span>
</span><span id="line-115"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Integer</span><span>          </span><span class="hs-comment">-- ^ Position in file</span><span>
</span><span id="line-116"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span>              </span><span class="hs-comment">-- ^ Size of mapped area</span><span>
</span><span id="line-117"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">b</span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- ^ Action</span><span>
</span><span id="line-118"></span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">b</span><span>
</span><span id="line-119"></span><span class="hs-identifier">withMappedArea</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">MappedObject</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">mh</span><span> </span><span class="hs-identifier">access</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">pos</span><span> </span><span class="hs-identifier">size</span><span> </span><span class="hs-identifier">act</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-120"></span><span>    </span><span class="hs-identifier">si</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getSystemInfo</span><span>
</span><span id="line-121"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">gran</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">siAllocationGranularity</span><span> </span><span class="hs-identifier">si</span><span>
</span><span id="line-122"></span><span>        </span><span class="hs-special">(</span><span class="hs-identifier">blocks</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">offset</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">divMod</span><span> </span><span class="hs-identifier">pos</span><span> </span><span class="hs-identifier">gran</span><span>
</span><span id="line-123"></span><span>        </span><span class="hs-identifier">start</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">blocks</span><span class="hs-operator">*</span><span class="hs-identifier">gran</span><span>
</span><span id="line-124"></span><span>        </span><span class="hs-identifier">size'</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">size</span><span> </span><span class="hs-operator">+</span><span> </span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">pos</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-identifier">start</span><span class="hs-special">)</span><span>
</span><span id="line-125"></span><span>    </span><span class="hs-identifier">bracket</span><span>
</span><span id="line-126"></span><span>        </span><span class="hs-special">(</span><span class="hs-identifier">mapViewOfFileEx</span><span> </span><span class="hs-identifier">mh</span><span> </span><span class="hs-identifier">access</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">start</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">size'</span><span> </span><span class="hs-identifier">nullPtr</span><span class="hs-special">)</span><span>
</span><span id="line-127"></span><span>        </span><span class="hs-special">(</span><span class="hs-identifier">unmapViewOfFile</span><span class="hs-special">)</span><span>
</span><span id="line-128"></span><span>        </span><span class="hs-special">(</span><span class="hs-identifier">act</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">flip</span><span> </span><span class="hs-identifier">plusPtr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">offset</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-129"></span><span>
</span><span id="line-130"></span><span class="hs-comment">---------------------------------------------------------------------------</span><span>
</span><span id="line-131"></span><span class="hs-comment">-- Enums</span><span>
</span><span id="line-132"></span><span class="hs-comment">---------------------------------------------------------------------------</span><span>
</span><span id="line-133"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">ProtectSectionFlags</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">DWORD</span><span>
</span><span id="line-134"></span><span class="hs-identifier">sEC_COMMIT</span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ProtectSectionFlags</span><span>
</span><span id="line-135"></span><span class="hs-identifier">sEC_COMMIT</span><span>     </span><span class="hs-glyph">=</span><span>  </span><span class="hs-number">134217728</span><span>
</span><span id="line-136"></span><span class="hs-identifier">sEC_IMAGE</span><span>      </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ProtectSectionFlags</span><span>
</span><span id="line-137"></span><span class="hs-identifier">sEC_IMAGE</span><span>      </span><span class="hs-glyph">=</span><span>  </span><span class="hs-number">16777216</span><span>
</span><span id="line-138"></span><span class="hs-identifier">sEC_NOCACHE</span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ProtectSectionFlags</span><span>
</span><span id="line-139"></span><span class="hs-identifier">sEC_NOCACHE</span><span>    </span><span class="hs-glyph">=</span><span>  </span><span class="hs-number">268435456</span><span>
</span><span id="line-140"></span><span class="hs-identifier">sEC_RESERVE</span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ProtectSectionFlags</span><span>
</span><span id="line-141"></span><span class="hs-identifier">sEC_RESERVE</span><span>    </span><span class="hs-glyph">=</span><span>  </span><span class="hs-number">67108864</span><span>
</span><span id="line-142"></span><span>
</span><span id="line-143"></span><span class="hs-pragma">{-# LINE 140 &quot;libraries\\Win32\\System\\Win32\\FileMapping.hsc&quot; #-}</span><span>
</span><span id="line-140"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">FileMapAccess</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">DWORD</span><span>
</span><span id="line-141"></span><span class="hs-identifier">fILE_MAP_ALL_ACCESS</span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">FileMapAccess</span><span>
</span><span id="line-142"></span><span class="hs-identifier">fILE_MAP_ALL_ACCESS</span><span>    </span><span class="hs-glyph">=</span><span>  </span><span class="hs-number">983071</span><span>
</span><span id="line-143"></span><span class="hs-identifier">fILE_MAP_COPY</span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">FileMapAccess</span><span>
</span><span id="line-144"></span><span class="hs-identifier">fILE_MAP_COPY</span><span>          </span><span class="hs-glyph">=</span><span>  </span><span class="hs-number">1</span><span>
</span><span id="line-145"></span><span class="hs-identifier">fILE_MAP_READ</span><span>          </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">FileMapAccess</span><span>
</span><span id="line-146"></span><span class="hs-identifier">fILE_MAP_READ</span><span>          </span><span class="hs-glyph">=</span><span>  </span><span class="hs-number">4</span><span>
</span><span id="line-147"></span><span class="hs-identifier">fILE_MAP_WRITE</span><span>         </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">FileMapAccess</span><span>
</span><span id="line-148"></span><span class="hs-identifier">fILE_MAP_WRITE</span><span>         </span><span class="hs-glyph">=</span><span>  </span><span class="hs-number">2</span><span>
</span><span id="line-149"></span><span>
</span><span id="line-150"></span><span class="hs-pragma">{-# LINE 147 &quot;libraries\\Win32\\System\\Win32\\FileMapping.hsc&quot; #-}</span><span>
</span><span id="line-147"></span><span>
</span><span id="line-148"></span><span class="hs-comment">---------------------------------------------------------------------------</span><span>
</span><span id="line-149"></span><span class="hs-comment">-- API in Haskell</span><span>
</span><span id="line-150"></span><span class="hs-comment">---------------------------------------------------------------------------</span><span>
</span><span id="line-151"></span><span class="hs-identifier">createFileMapping</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">ProtectFlags</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DDWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-152"></span><span class="hs-identifier">createFileMapping</span><span> </span><span class="hs-identifier">mh</span><span> </span><span class="hs-identifier">flags</span><span> </span><span class="hs-identifier">mosize</span><span> </span><span class="hs-identifier">name</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-153"></span><span>    </span><span class="hs-identifier">maybeWith</span><span> </span><span class="hs-identifier">withTString</span><span> </span><span class="hs-identifier">name</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">c_name</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-154"></span><span>        </span><span class="hs-identifier">failIf</span><span> </span><span class="hs-special">(</span><span class="hs-operator">==</span><span class="hs-identifier">nullPtr</span><span class="hs-special">)</span><span> </span><span class="hs-string">&quot;createFileMapping: CreateFileMapping&quot;</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_CreateFileMapping</span><span> </span><span class="hs-identifier">handle</span><span> </span><span class="hs-identifier">nullPtr</span><span> </span><span class="hs-identifier">flags</span><span> </span><span class="hs-identifier">moshi</span><span> </span><span class="hs-identifier">moslow</span><span> </span><span class="hs-identifier">c_name</span><span>
</span><span id="line-155"></span><span>    </span><span class="hs-keyword">where</span><span>
</span><span id="line-156"></span><span>        </span><span class="hs-special">(</span><span class="hs-identifier">moshi</span><span class="hs-special">,</span><span class="hs-identifier">moslow</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ddwordToDwords</span><span> </span><span class="hs-identifier">mosize</span><span>
</span><span id="line-157"></span><span>        </span><span class="hs-identifier">handle</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">maybe</span><span> </span><span class="hs-identifier">iNVALID_HANDLE_VALUE</span><span> </span><span class="hs-identifier">id</span><span> </span><span class="hs-identifier">mh</span><span>
</span><span id="line-158"></span><span>
</span><span id="line-159"></span><span class="hs-identifier">openFileMapping</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">FileMapAccess</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">BOOL</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-160"></span><span class="hs-identifier">openFileMapping</span><span> </span><span class="hs-identifier">access</span><span> </span><span class="hs-identifier">inherit</span><span> </span><span class="hs-identifier">name</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-161"></span><span>    </span><span class="hs-identifier">maybeWith</span><span> </span><span class="hs-identifier">withTString</span><span> </span><span class="hs-identifier">name</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">c_name</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-162"></span><span>        </span><span class="hs-identifier">failIf</span><span> </span><span class="hs-special">(</span><span class="hs-operator">==</span><span class="hs-identifier">nullPtr</span><span class="hs-special">)</span><span> </span><span class="hs-string">&quot;openFileMapping: OpenFileMapping&quot;</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-163"></span><span>            </span><span class="hs-identifier">c_OpenFileMapping</span><span> </span><span class="hs-identifier">access</span><span> </span><span class="hs-identifier">inherit</span><span> </span><span class="hs-identifier">c_name</span><span>
</span><span id="line-164"></span><span>
</span><span id="line-165"></span><span class="hs-identifier">mapViewOfFileEx</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">FileMapAccess</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DDWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">SIZE_T</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">b</span><span class="hs-special">)</span><span>
</span><span id="line-166"></span><span class="hs-identifier">mapViewOfFileEx</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">access</span><span> </span><span class="hs-identifier">offset</span><span> </span><span class="hs-identifier">size</span><span> </span><span class="hs-identifier">base</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-167"></span><span>    </span><span class="hs-identifier">failIfNull</span><span> </span><span class="hs-string">&quot;mapViewOfFile(Ex): c_MapViewOfFileEx&quot;</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-168"></span><span>        </span><span class="hs-identifier">c_MapViewOfFileEx</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">access</span><span> </span><span class="hs-identifier">ohi</span><span> </span><span class="hs-identifier">olow</span><span> </span><span class="hs-identifier">size</span><span> </span><span class="hs-identifier">base</span><span>
</span><span id="line-169"></span><span>    </span><span class="hs-keyword">where</span><span>
</span><span id="line-170"></span><span>        </span><span class="hs-special">(</span><span class="hs-identifier">ohi</span><span class="hs-special">,</span><span class="hs-identifier">olow</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ddwordToDwords</span><span> </span><span class="hs-identifier">offset</span><span>
</span><span id="line-171"></span><span>
</span><span id="line-172"></span><span class="hs-identifier">mapViewOfFile</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">FileMapAccess</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DDWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">SIZE_T</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span>
</span><span id="line-173"></span><span class="hs-identifier">mapViewOfFile</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-identifier">o</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">mapViewOfFileEx</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-identifier">o</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-174"></span><span>
</span><span id="line-175"></span><span class="hs-identifier">unmapViewOfFile</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-176"></span><span class="hs-identifier">unmapViewOfFile</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">c_UnmapViewOfFile</span><span> </span><span class="hs-identifier">v</span><span> </span><span class="hs-operator">&gt;&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-177"></span><span>
</span><span id="line-178"></span><span class="hs-comment">---------------------------------------------------------------------------</span><span>
</span><span id="line-179"></span><span class="hs-comment">-- Imports</span><span>
</span><span id="line-180"></span><span class="hs-comment">---------------------------------------------------------------------------</span><span>
</span><span id="line-181"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h OpenFileMappingW&quot;</span><span>
</span><span id="line-182"></span><span>    </span><span class="hs-identifier">c_OpenFileMapping</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">BOOL</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LPCTSTR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-183"></span><span>
</span><span id="line-184"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h CreateFileMappingW&quot;</span><span>
</span><span id="line-185"></span><span>    </span><span class="hs-identifier">c_CreateFileMapping</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LPCTSTR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">HANDLE</span><span>
</span><span id="line-186"></span><span>
</span><span id="line-187"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h MapViewOfFileEx&quot;</span><span>
</span><span id="line-188"></span><span>    </span><span class="hs-identifier">c_MapViewOfFileEx</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">SIZE_T</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">b</span><span class="hs-special">)</span><span>
</span><span id="line-189"></span><span>
</span><span id="line-190"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h UnmapViewOfFile&quot;</span><span>
</span><span id="line-191"></span><span>    </span><span class="hs-identifier">c_UnmapViewOfFile</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">BOOL</span><span>
</span><span id="line-192"></span><span>
</span><span id="line-193"></span><span class="hs-pragma">{-# CFILES cbits/HsWin32.c #-}</span><span>
</span><span id="line-194"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-string">&quot;HsWin32.h &amp;UnmapViewOfFileFinaliser&quot;</span><span>
</span><span id="line-195"></span><span>    </span><span class="hs-identifier">c_UnmapViewOfFileFinaliser</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">FunPtr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-196"></span></pre></body></html>